home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / DOSTIPS2.ZIP / DOSMENUS.TXT < prev    next >
Text File  |  1985-11-24  |  11KB  |  296 lines

  1.                             DOS Menu Magic
  2.          (PC Magazine Vol 4 No 6 March 19, 1985 User-to-User)
  3.  
  4.      If you use DOS 2.x or higher and have ever abandoned a batch file 
  5. idea for lack of a way to direct execution based on user input, the 8-
  6. byte GETKEY.COM utility, when invoked from within a batch file, will 
  7. return the ASCII value corresponding to a single keystroke.  This value 
  8. can then be tested with the batch IF ERRORLEVEL facility.  Create
  9. GETKEY.COM using DEBUG:
  10.  
  11. A>DEBUG
  12. -E 100 B4 00 CD 16 B4 4C CD 21
  13. -N B:GETKEY.COM
  14. -R CX
  15. CX 0000
  16. :8
  17. -W
  18. Writing 0008 bytes
  19. -Q
  20.  
  21.      One important thing to keep in mind is that the batch test IF 
  22. ERRORLEVEL xx will be considered true if xx is less than or equal to 
  23. the GETKEY return code.  It is therefore necessary to compare the
  24. return code to its possible values in reverse-ASCII order.  Copy
  25. BASIC.COM and BASICA.COM to your disk if you wish to test the sample
  26. MENU.BAT file shown here:
  27.      
  28. ECHO OFF
  29. :BEG
  30. CLS
  31. ECHO ----------------------
  32. ECHO 1 - Run BASIC
  33. ECHO 2 - Run Advanced BASIC
  34. ECHO 3 - Return to DOS
  35. ECHO ----------------------
  36. :ASK
  37. ECHO Hit 1, 2 or 3
  38. GETKEY
  39. IF ERRORLEVEL 52 GOTO ASK
  40. IF ERRORLEVEL 51 GOTO K3
  41. IF ERRORLEVEL 50 GOTO K2
  42. IF ERRORLEVEL 49 GOTO K1
  43. GOTO ASK
  44. :K1
  45. BASIC
  46. GOTO BEG
  47. :K2
  48. BASICA
  49. GOTO BEG
  50. :K3
  51. ECHO OK!
  52.  
  53. Editor's Note:  The only thing users may want to add is a series of IF 
  54. EXISTs to better inform the user if one of the menu selections is not 
  55. on the disk, e.g., use the addition below and put it between line :K1 
  56. and BASIC to check if BASIC.COM is on the disk:
  57.  
  58. IF EXIST BASIC THEN GOTO B1
  59. ECHO BASIC.COM IS NOT ON THIS DISK
  60. PAUSE
  61. GOTO :BEG
  62. :B1
  63.  
  64. -----------------------------------------------------------------
  65.                           More DOS Menu Magic
  66.          (PC Magazine Vol 4 No 15 July 23, 1985 User-to-User)
  67.  
  68.      The User-to-User submission in Vol 4 No 6 (above) contained 
  69. instructions for creating GETKEY.COM, a simple program that accepts 
  70. keyboard input in a batch file.  The ASCII value of a key is returned
  71. in the ERRORLEVEL, which can be accessed by statements of the type "IF 
  72. ERRORLEVEL ## <do something>".  A slight variation called GETFUN.COM 
  73. will let you use function keys as inputs for GETKEY (Figure 1).
  74.      GETFUN.COM returns the extended scan code for the function keys 
  75. (and other keys -- Figure 2) and returns 255 if a nonspecial key is 
  76. pressed.  As was explained, the "IF ERRORLEVEL" condition is true if
  77. the error level is less than or equal to the returned code.  A batch
  78. file created around GETFUN should have the following features (Figure
  79. 3):
  80.      1. There must be a label, such as :CHOICE, just before the call to
  81. GETFUN, and another, such as :BEGIN, before any lines that display a
  82. menu.
  83.      2. The IF ERRORLEVEL statements must be in descending numerical
  84. order and should be a continuous sequence. If they can't be continuous,
  85. holes must be filled with statements that transfer control back to
  86. CHOICE (e.g., IF ERRORLEVEL 71 GOTO CHOICE).
  87.      3. Since the user may press keys other than those we expect, put a
  88. line just before the highest ERRORLEVEL that says IF ERRORLEVEL 
  89. (highest+1) GOTO CHOICE.
  90.      4. To catch keys pressed with a lower value than expected just
  91. after the sequence of IF ERRORLEVEL, put in a simple GOTO CHOICE.
  92.      5. Each section of code that is GONE TO should end with a GOTO
  93. BEGIN.
  94.      The "heart" of GETFUN and GETKEY is the call to DOS function 4C, 
  95. which sets the ERRORLEVEL to the value in AL.  When called with 0 in
  96. AH, interrupt 16h returns the ASCII value of the key in AL.  Certain
  97. keys, such as function or arrow keys, have no ASCII value -- in these
  98. cases AL gets a zero, and a special code goes in AH.  GETFUN checks for
  99. this zero.  If it's found, the special code is moved from AH to AL and
  100. the ERRORLEVEL is set to it.  If the key was not special, AL is filled
  101. with FF (decimal 255).  Thus any nonspecial key will have a higher
  102. ERRORLEVEL than any special key.
  103.      The usefulness of this procedure is immense in a big batch file 
  104. menu system on a hard disk.  In this case, 40 small batch files with 
  105. names A.BAT, B.BAT, and so on were converted into one big batch file. 
  106. Since each file on the hard disk takes 4K (cluster of 8 sectors), this 
  107. was a huge saving of wasted space.
  108.      Editor's Note:  The ERRORLEVEL menu trick is rapidly gaining in 
  109. popularity, as it doesn't force users to hit the Enter key to enter 
  110. their menu choices.  Mr. Rubenking sent this submission along with a 
  111. menu-driven set of shareware programs he calls PIANOMAN.  If you're 
  112. interested in a program that very cleverly lets you play your PC like a 
  113. piano, and comes with a slew of interesting classical pieces 
  114. (including the theme to Monty Python's Flying Circus and The Lone 
  115. Ranger) already keyed in and ready to play at the touch of a function 
  116. key, contact him at:
  117.           Mr. Neil J. Rubenking
  118.           300 Page Street
  119.           San Francisco, CA  94102
  120. - - - - -
  121. Figure 1: GETFUN.COM
  122. A>debug getfun.com
  123. File not found
  124. -a 100
  125. -xxxx:0100   MOV AH,00
  126. -xxxx:0102   INT 16
  127. -xxxx:0104   CMP AL,00
  128. -xxxx:0106   JZ  010C
  129. -xxxx:0108   MOV AL,FF
  130. -xxxx:010A   JMP 010E
  131. -xxxx:010C   MOV AL,AH
  132. -xxxx:010E   MOV AH,4C
  133. -xxxx:0110   INT 21
  134. -xxxx:0112
  135. -rcx
  136. 0000
  137. :0012
  138. -w
  139. Writing 0012 bytes
  140. -q
  141. - - - - -
  142. Figure 2: Extended keyboard scan codes for GETFUN.COM
  143.  
  144.              FUNCTION KEYS
  145. F1 ...F10      unshifted      59 ...68
  146. F1 ...F10      shift          84 ...93
  147. F1 ...F10      Ctrl           94 ...103
  148. F1 ...F10      Alt            104 ...113
  149.  
  150.              KEYPAD KEYS
  151.         unshifted        Ctrl
  152. Home        71            119
  153. Up          72
  154. PgUp        73            132
  155. Left        75            115
  156. Right       77            116
  157. End         79            117
  158. Down        80
  159. PgDn        81            118
  160. Ins         82
  161. Del         83
  162.  
  163.  
  164.     ALT + REGULAR KEY
  165. QWERTYUIOP     16 ...25
  166. ASDFGHJKL      30 ...38
  167. ZXCVBNM        44 ...50
  168. 1234567890-=   120 ...131
  169. - - - - -
  170. Figure 3:  Sample menu allows GETFUN.KEY to use function keys to select
  171. menu choices.
  172. ECHO OFF
  173. CLS
  174. :BEGIN
  175. ECHO ------------MENU:-------------
  176. ECHO     F1    SPACE PERVADERS
  177. ECHO     F2    WORDSTAR
  178. ECHO     F3    DBASE
  179. ECHO     F4    EXIT TO DOS
  180. ECHO PRESS A FUNCTION KEY TO CHOICE
  181. ECHO ------------------------------
  182. :CHOICE
  183. GETFUN
  184. IF ERRORLEVEL 63 GOTO CHOICE
  185. IF ERRORLEVEL 62 GOTO EXIT
  186. IF ERRORLEVEL 61 GOTO DBAS
  187. IF ERRORLEVEL 60 GOTO WRD
  188. IF ERRORLEVEL 59 GOTO SPACE
  189. GOTO CHOICE
  190. :SPACE
  191. BASICA PERVADER
  192. GOTO BEGIN
  193. :WRD
  194. WS
  195. GOTO BEGIN
  196. :DBAS
  197. DBASE
  198. GOTO BEGIN
  199. :EXIT
  200. CLS
  201.  
  202. -----------------------------------------------------------------
  203.                        Automated DOS Menus
  204.     (from PC Magazine Vol 4 No 14 July 9, 1985 User-to-User)
  205.  
  206.      The CHOOSE.COM program (created with CHOOSE.BAS) along with the 
  207. batch file MENU.BAT can provide you with a simple way to eliminate 
  208. repetitive typing of those DOS commands that you use most frequently. 
  209. These two programs let you assign your most often used program names, 
  210. batch files, or DOS commands to single-key menu entries.  MENU.BAT 
  211. displays a menu on the screen (by typing MENU.SCR) and then invokes 
  212. CHOOSE.COM.  CHOOSE.COM uses function 4C hex of interrupt 21 hex to
  213. set the DOS ERRORLEVEL value in response to a struck key.  MENU.BAT
  214. then evaluates the user's choice via the IF ERRORLEVEL subcommand. 
  215. CHOOSE.COM can set the ERRORLEVEL to any value, 0-9.  When using the
  216. IF ERRORLEVEL command in your batch files, always check the numbers in 
  217. descending order because any value that is below or equal to the actual 
  218. ERRORLEVEL value will return a true reading.
  219.      Editor's Note:  This is a spiffy way to create menus since it
  220. saves the user the trouble of needing to hit the Enter key after each 
  221. numerical menu selection is made.  To use this, you'll need the 
  222. CHOOSE.COM file (by running CHOOSE.BAS), your own MENU.SCR file, and 
  223. your own MENU.BAT file.  You can adapt the ones below.  When these
  224. files are on your disk, just type MENU, or include MENU as a command
  225. in your AUTOEXEC.BAT file.
  226. - - - - -
  227. CHOOSE.BAS:
  228. 100 'CHOOSE.BAS: Creates CHOOSE.COM DOS menu.
  229. 110 DEFINT A-Z:TOTAL=0
  230. 120 FOR A=1 TO 114:READ A$:B=VAL("&H"+A$):TOTAL=TOTAL+B:NEXT
  231. 130 IF TOTAL<>12866 THEN PRINT "Check your typing!":END
  232. 140 RESTORE
  233. 150 OPEN "CHOOSE.COM" FOR OUTPUT AS #1
  234. 160 FOR A=1 TO 114:READ A$:PRINT #1,CHR$(VAL("&H"+A$));:NEXT
  235. 170 CLOSE:PRINT "CHOOSE.COM created."
  236. 180 END
  237. 190 DATA B8,00,00,CD,16,80,FC,02,74,32,80,FC,03,74,32,80
  238. 200 DATA FC,04,74,32,80,FC,05,74,32,80,FC,06,74,32,00,FC
  239. 210 DATA 07,74,32,80,FC,08,74,32,80,FC,09,74,32,80,FC,0A
  240. 220 DATA 74,32,80,FC,0B,74,32,B0,00,EB,33,90,B0,01,EB,2E
  241. 230 DATA 90,B0,02,EB,29,90,B0,03,EB,24,90,B0,04,EB,1F,90
  242. 240 DATA B0,05,EB,1A,90,B0,06,EB,15,90,B0,07,EB,10,90,B0
  243. 250 DATA 08,EB,0B,90,B0,09,EB,06,90,B0,00,EB,01,90,B4,4C
  244. 260 DATA CD,21
  245. - - - - -
  246. MENU.BAT batch file (top) and MENU.SCR display (bottom). Adapt these to 
  247. suit your needs and make sure the 1 through 8 entries match in both:
  248.  
  249. REM MENU.BAT
  250. echo off
  251. cls
  252. type menu.scr
  253. echo *** Choose Function ***
  254. choose
  255. if errorlevel 8 goto end
  256. if errorlevel 7 basica draw5/M:&HEF50
  257. if errorlevel 6 advent me
  258. if errorlevel 5 basica keys
  259. if errorlevel 4 talk128
  260. if errorlevel 3 turbo
  261. if errorlevel 2 ws
  262. if errorlevel 1 dbase maillst.prg
  263. :end
  264. cls
  265.  
  266.  
  267. ****** System Menu ******
  268.  
  269. 1.  dBase II Mailing List
  270. 2.  WordStar
  271. 3.  Pascal
  272. 4.  Telecommunicate
  273. 5.  Basic
  274. 6.  Adventure Game
  275. 7.  Draw Pictures
  276. 8.  Exit to DOS
  277.  
  278. -----------------------------------------------------------------
  279.                                MENU.BAS
  280.           (PC Magazine Vol 4 No 7 April 2, 1985 User-to-User)
  281.  
  282.      If you're using DOS 2.0 or above, the AUTOMENU.BAT batch file and 
  283. the MENU.BAS program will automatically generate a menu that lets you 
  284. access your BASIC programs.  AUTOMENU.BAT redirects your directory to 
  285. MENU.DIR, first piping it through the DOS SORT filter to put your files 
  286. in alphabetical order. MENU.BAS extracts data from MENU.DIR, sets up 
  287. the display, and lets you select a program by typing in its number.
  288.      Line 170 of MENU.BAS determines which extensions the program will 
  289. accept, and currently ignores all extensions other than .BAS and .REM.  
  290. To list other extensions, add them to this line.  The program works
  291. fine so long as there aren't an execssive number of BASIC files on a 
  292. particular disk.  To create AUTOMENU.BAT:
  293.           COPY CON:AUTOMENU.BAT
  294.           DIR|SORT>MENU.DIR
  295.           BASICA MENU.BAS
  296.